package com.share.web.action.attach.advertise;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.share.bean.attach.advertise.PositionItem;
import com.share.service.attach.advertise.PositionItemManager;
import com.share.service.attach.advertise.PositionSortManager;
import com.share.web.action.base.BaseActionSupport;

@Controller
@Scope("prototype")
public class PositionItemAction extends BaseActionSupport{

	private static final long serialVersionUID = 1L;

	private PositionItem pi ;
	
	@Resource
	private PositionItemManager pim ;
	
	@Resource
	private PositionSortManager psmgr ;
	
	public String addPositionItem() throws Exception {
		this.pim.savePositionItemManager(pi) ;
		
		return SUCCESS ;
	}
	
	public String updatePi() throws Exception {
		this.pim.updatePositionItemManager(pi) ;
		this.getBaseform().getRequest().setAttribute("redirectUrl","/share/attach/positionItem!loadAllPi.action?pi.piId="+pi.getAdPS().getPsId());
		
		return "pub_update_success" ;
	}
	
	public String deleteByIdPi() throws Exception {
		
		this.pim.deletePositionItemManager(pi.getPiId()) ;
		
		return SUCCESS ;
	}
	
	public String loadByIdPi() throws Exception {
		this.getBaseform().getRequest().setAttribute("pi",this.pim.loadByIdPositionItemManager(pi.getPiId())) ;
		
		if("updatePi".equals(this.getBaseform().getType())) {
			this.getBaseform().getRequest().setAttribute("psList",this.psmgr.findAllPositionSortManager()) ;
			
			return "updatePi" ;
		}
		return null ;
	}
	
	public String loadAllPi() throws Exception {
		this.getBaseform().getRequest().setAttribute("piList",this.pim.findAllPositionItemManager(pi.getPiId())) ;
		return "loadAll" ;
	}
	

	public PositionItem getPi() {
		return pi;
	}

	public PositionItemManager getPim() {
		return pim;
	}

	public void setPi(PositionItem pi) {
		this.pi = pi;
	}

	public void setPim(PositionItemManager pim) {
		this.pim = pim;
	}
	
	public void setPsmgr(PositionSortManager psmgr) {
		this.psmgr = psmgr;
	}
	
}
